package com.carpo.springtx;

import java.util.ArrayList;
import java.util.List;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.util.UriComponentsBuilder;

import com.carpo.springtx.model.Spittle;

/**
 * 
 * 此处填写类简介
 * <p>
 * 此处填写类说明
 * </p>
 * @author liuhl-b
 * @since jdk1.6
 * 2018年4月16日
 *  
 */

@RestController
@RequestMapping("/spittle")
public class RestfulController {

	@RequestMapping(value="/list")
	public List<Spittle> spittles(){
		List<Spittle> list = new ArrayList<Spittle>();
		Spittle s = new Spittle();
		s.setId("1");
		s.setName("zhangsan");
		s.setAge("15");
		
		Spittle s1 = new Spittle();
		s1.setId("2");
		s1.setName("lisi");
		s1.setAge("12");
		
		list.add(s);
		list.add(s1);
		return list;
	}
	
	@RequestMapping(value="/{id}", method=RequestMethod.GET)
	public ResponseEntity<Spittle> spittleById(@PathVariable String id, UriComponentsBuilder ucb){
		System.out.println("1111");
		System.out.println(ucb.path("/spittle").build().toUri());
		System.out.println("2222");
		Spittle spittle = null;
		HttpStatus status = HttpStatus.NOT_FOUND;
		return new ResponseEntity<Spittle>(spittle, status);
		
	}
}
